package Entity;

import java.sql.ResultSet;
import java.util.Date;
import Control.CommonControls;
import Control.NeedyResident_UpdateUser_Control;

import Control.MySQLController;
import Form.NeedyResident_UpdateUser_Form;

public class NeedyResident_UpdateAccount extends User{

	public NeedyResident_UpdateAccount(String nric, String name,
		String email, int contact_no, Date dob,
		String address, char gender, String user_status_code,
		String password) {
	super(nric, name, email, contact_no, dob, address, gender,
			user_status_code, password);
		// TODO Auto-generated constructor stub
	}
	
	public NeedyResident_UpdateAccount() {
		// TODO Auto-generated constructor stub
	}

	private static double monthlySalary;
	private String location;
	private String postalCode;
	private static int familySize;
	private String race;
	
	public static double getMonthlySalary() {
		return monthlySalary;
	}

	public void setMonthlySalary(double monthlySalary) {
		NeedyResident_UpdateAccount.monthlySalary = monthlySalary;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public static int getFamilySize() {
		return familySize;
	}

	public void setFamilySize(int familySize) {
		NeedyResident_UpdateAccount.familySize = familySize;
	}

	public String getRace() {
		return race;
	}

	public void setRace(String race) {
		this.race = race;
	}
	
	public boolean UpdateNeedyResident(){
		boolean success = false;
		MySQLController db = new MySQLController();
		db.getConnection();
		//update into User database
		String sql = "UPDATE ooadpj.user";
		sql += " Set password ='" + getPassword() + "', email ='" + getEmail() + "', contact_no = "+ getContact_no() + " , address = '" + getAddress() +"'";
		sql += " WHERE nric = '" + getNric()+"'";
		//update into Needy resident database
		String sql2 = "UPDATE ooadpj.needy_resident";
		sql2 += " SET monthly_income = '" + getMonthlySalary() + "', family_size = '" + getFamilySize() + "'";
		sql2 += " Where nric = '" + getNric() +"'";
		if(db.updateRequest(sql)==1 && db.updateRequest(sql2)==1)
			success = true;
		return success;
	}
		
}
